#pragma once
#include "mpp/rk_struct.h"
#include "base_pusher.h"

namespace stream {

typedef void *MppEncRefCfg;

class RKStreamPusher:public BasePusher
{
public:
  RKStreamPusher(StreamPusherInfo* spifo, LogInfo* log_info);
  ~RKStreamPusher();

public:
  int init_params();
  int start_push();
  int stop_push();
  int add_frame(stream::ImageBlob& buffer);

private:
  int start_push_imp();
  int start_push_listener();

  int init_pusher_params();
  int init_venc_params();
  MPP_RET enc_ctx_init(MpiEncData **data, MpiEncArgs *cmd);
  MPP_RET mpp_enc_cfg_setup_t(MpiEncData *p);
  MPP_RET GetHeader(SpsHeader *sps_header);
  void release_ffmpeg();
  void deinit();
  MPP_RET enc_ctx_deinit(MpiEncData **data);


private:
  std::mutex queue_lock;
  std::queue<stream::ImageBlob> queue_data;

  AVFormatContext *pfmt_ctx = nullptr;
  AVCodec *out_codec = nullptr;
  AVStream *out_stream = nullptr;
  AVCodecContext *out_codec_ctx = nullptr;

  // init module
  void *encoder = nullptr;
  void *vps = nullptr;

  //rk_mpp
  MpiEncArgs args_;
	MpiEncData *p;
  SpsHeader sps_header;
  //headinfo
  // char head_buf[100];
  // uint32_t head_len;
  std::atomic_int encode_put_frame_flag;
};


}   // namespace camera
